package com.sunny.design.singleton.hungry;

/**
 * 饿汉式单例
 *  在单例类首次加载时就创建实例
 *
 * 缺点：
 *  浪费内存空间
 *
 * @author Sunny
 * @date 2019/12/29 15:33
 */
public class HungrySingleton {
    private HungrySingleton(){
        if (instance != null) {
            throw new RuntimeException("不允许反射创建!");
        }
    }

    private static final HungrySingleton instance = new HungrySingleton();

    public static HungrySingleton getInstance() {
        return instance;
    }
}
